﻿// -----------------------------------------------------------------------
// <copyright file="ResourceStringSource.cs" company="Moveax, LLC">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.Pluralization.Core
{
    using System.Globalization;
    using System.Resources;

    /// <summary>Returns pluralized and localized strings from associated resource.</summary>
    public class ResourceStringsSource : ILocalizedStringsSource
    {
        private readonly ResourceManager _resourceManager;

        /// <summary>Initializes a new instance of the <see cref="ResourceStringsSource"/> class.</summary>
        /// <param name="resourceManager">The resource manager.</param>
        public ResourceStringsSource(ResourceManager resourceManager)
        {
            this._resourceManager = resourceManager;
        }

        /// <summary>Returns the value of the string resource pluralized and localized for the specified culture.</summary>
        /// <param name="name">The name of the string to retrieve.</param>
        /// <param name="pluralCategory">The plural category.</param>
        /// <param name="cultureInfo">An object that represents the culture for which the resource is localized.</param>
        /// <returns>The value of the resource pluralized and localized for the specified culture, or null if nothing appropriate cannot be found.</returns>
        public string GetString(string name, PluralCategory pluralCategory, CultureInfo cultureInfo)
        {
            var pluralName = string.Format("{0}{1}", name, pluralCategory.ToString());
            return this._resourceManager.GetString(pluralName, cultureInfo);
        }
    }
}
